package com.tiancheng.trade.merchant.channel;

import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.commom.core.exception.BusinessException;
import com.tiancheng.trade.commom.core.utils.ServiceLocator;
import com.tiancheng.trade.merchant.channel.handler.gaocheng.GcMerchantRegChannel;
import com.tiancheng.trade.merchant.channel.handler.ums.UmsMerchantRegChannel;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付渠道工厂
 *
 * @author kellen
 * @date 2024/4/16
 */
public class PayChannelFactory {

    private static Map<String, Class> payChannelMap = new HashMap<>();

    static {
        payChannelMap.put(PaymentChannelEnum.UMS.getCode(), UmsMerchantRegChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_DHJT.getCode(), UmsMerchantRegChannel.class);
        payChannelMap.put(PaymentChannelEnum.gao_cheng_nong_hang.getCode(), GcMerchantRegChannel.class);
    }

    /**
     * 获取支付渠道
     * @param channel 支付渠道编码
     * @return
     * @throws BusinessException
     */
    public static AbstractMerchantRegChannel get(String channel) throws BusinessException {
        return (AbstractMerchantRegChannel) ServiceLocator.getBean(payChannelMap.get(channel));
    }
}
